package com.kob.backend.service.impl.user.task;

import com.kob.backend.mapper.TaskMapper;
import com.kob.backend.pojo.Task;
import com.kob.backend.service.user.task.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class TaskServiceImpl implements TaskService {

    @Autowired
    private TaskMapper taskMapper;

    public List<Task> getTask(){
        List<Task> taskList = taskMapper.selectList(null);
        return taskList;
    }

    public Map<String,String> addTask(String taskname,String taskinfo){
        Task task = new Task();
        task.setTaskname(taskname);
        task.setTaskinfo(taskinfo);
        taskMapper.insert(task);
        Map<String, String> map = new HashMap<>();
        map.put("error_message", "success");
        return map;
    }

    public Task selectTaskById(int id){
        return taskMapper.selectById(id);
    }

    public Task takeTaskById(int id){
        Task task = taskMapper.selectById(id);
        taskMapper.deleteById(id);
        return task;
    }
}
